package com.finalministry.server;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.finalministry.database.dao.DaoFactory;
import org.finalministry.objects.Territory;

@Path("/territories")
public class ButtonTerritories {

	@GET
	@Produces(MediaType.APPLICATION_XHTML_XML + ";charset=utf-8")
	public String loadAllTerritories() throws Exception {

		List<Territory> territories = DaoFactory.getInstance().getTerritoryDAO().getAll();
		StringBuffer htm = new StringBuffer();

		htm.append("<div><a href=\"#\" class=\"btn btn-lg btn-default\">Learn how to manage the territories</a>");
		htm.append("<table class=\"table\">");

		for (Territory territory : territories) {
			htm.append("<tr><td>");
			htm.append(territory.getNumber());
			htm.append("</td><td>");
			htm.append(territory.getCity());
			htm.append("</td></tr>");
		}

		htm.append("</table></div>");

		return htm.toString();
	}
}
